<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://a42.vodafone.com/versions/all/v1.0"
    xmlns:tns="http://a42.vodafone.com/versions/all/v1.0"
    elementFormDefault="qualified"
>

    <!-- XML schema 1.0 legacy!!! -->

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Definition of XML representations for purchase history resources and related DTOs. -->
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Import the common types for A42 resources. -->
    <xs:include schemaLocation="a42.xsd" />
    <!-- Import the referenced types for simple content catalog resources. -->
    <xs:include schemaLocation="sc2.xsd" />
    <!-- Import the referenced types for simple purchase history resources. -->
    <xs:include schemaLocation="sph.xsd" />

    <!-- Specific link types with defined link relation types. -->
    <xs:complexType name="AllPurchaseOrdersLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/allPurchaseOrders" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchaseOrdersLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/purchaseOrders" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchaseOrderLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/purchaseOrder" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchaseOrderCancellationLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/cancellation" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchaseOrderPaymentLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/payment" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="PurchaseOrderItemLinkType">
        <xs:complexContent>
            <xs:restriction base="tns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseApi/purchaseOrderItem" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Representation for the service document for this API. -->
    <xs:element name="spaServiceDocument">
        <xs:complexType>
            <xs:sequence>
                <!-- Root link for provisioning and deprovisioning only for admin authorization. -->
                <xs:element name="allPurchaseOrdersRootLink" type="tns:AllPurchaseOrdersLinkType" minOccurs="0" maxOccurs="1" />
                <!-- Root link for particular purchase history only for a provisioned user. -->
                <xs:element name="purchaseOrdersRootLink" type="tns:PurchaseOrdersLinkType" minOccurs="0" maxOccurs="1" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- Representation for a collection of the individual purchase order collections of users. Retrieval to be used with care! -->
    <xs:element name="allPurchaseOrders" type="tns:AllPurchaseOrdersType" />
    <xs:complexType name="AllPurchaseOrdersType">
        <xs:complexContent>
            <xs:extension base="tns:PaginatableResourceType">
                <xs:sequence>
                    <!-- The actual collection of resource links. -->
                    <xs:element name="items" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice>
                                <xs:sequence>
                                    <xs:element name="purchaseOrders" type="tns:PurchaseOrdersType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                                <xs:sequence>
                                    <xs:element name="link" type="tns:PurchaseOrdersLinkType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- Representation for a collection resource that aggregates purchase history entities. -->
    <xs:element name="purchaseOrders" type="tns:PurchaseOrdersType" />
    <xs:complexType name="PurchaseOrdersType">
        <xs:complexContent>
            <xs:extension base="tns:PaginatableResourceType">
                <xs:sequence>
                    <!-- The collection will be related to a particular user in most cases. -->
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <!-- The actual collection of resource links. -->
                    <xs:element name="items" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice>
                                <xs:sequence>
                                    <xs:element name="purchaseOrder" type="tns:PurchaseOrderType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                                <xs:sequence>
                                    <xs:element name="link" type="tns:PurchaseOrderLinkType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <xs:element name="purchaseOrder" type="tns:PurchaseOrderType" />
    <xs:complexType name="PurchaseOrderType">
        <xs:complexContent>
            <xs:extension base="tns:PaginatableResourceType">
                <xs:sequence>
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <xs:element name="cancellation" type="tns:PurchaseOrderCancellationLinkType" minOccurs="0" maxOccurs="1" />
                    <xs:element name="payment" type="tns:PurchaseOrderPaymentLinkType" minOccurs="0" maxOccurs="1" />
                    <xs:element name="totalPrice" type="xs:double" minOccurs="0" maxOccurs="1" />
                    <xs:element name="currency" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <!-- The personal collection of all purchase orders of the particular user. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="purchaseOrdersLink" type="tns:PurchaseOrdersLinkType" />
                        <xs:element name="purchaseOrders" type="tns:PurchaseOrdersType" />
                    </xs:choice>
                    <xs:element name="items" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice>
                                <xs:sequence>
                                    <xs:element name="purchaseOrderItem" type="tns:PurchaseOrderItemType" minOccurs="0"
                                        maxOccurs="unbounded" />
                                </xs:sequence>
                                <xs:sequence>
                                    <xs:element name="link" type="tns:PurchaseOrderItemLinkType" minOccurs="0" maxOccurs="unbounded" />
                                </xs:sequence>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:element name="purchaseOrderItem" type="tns:PurchaseOrderItemType" />
    <xs:complexType name="PurchaseOrderItemType">
        <xs:complexContent>
            <xs:extension base="tns:ResourceType">
                <xs:sequence>
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="purchaseOrderLink" type="tns:PurchaseOrderLinkType" />
                        <xs:element name="purchaseOrder" type="tns:PurchaseOrderType" />
                    </xs:choice>
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="catalogItemLink" type="tns:CatalogItemLinkType" />
                        <xs:element name="catalogItem" type="tns:CatalogItemType" />
                    </xs:choice>
                    <!-- After a payment was successfully done, the purchased items are referenced. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="purchasedItemsLink" type="tns:PurchasedItemsLinkType" />
                        <xs:element name="purchasedItems" type="tns:PurchasedItemsType" />
                    </xs:choice>
                    <xs:element name="amount" type="xs:int" minOccurs="0" maxOccurs="1" />
                    <!-- The price the user has to pay / has paid for the purchase: unit price. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="unitPrice" type="xs:double" />
                        <xs:element name="unitPriceTag" type="xs:string" />
                    </xs:choice>
                    <!-- The price the user has to pay / has paid for the purchase: line item price. -->
                    <xs:choice minOccurs="0" maxOccurs="1">
                        <xs:element name="lineItemPrice" type="xs:double" />
                        <xs:element name="lineItemPriceTag" type="xs:string" />
                    </xs:choice>
                    <!-- The currency used to execute the purchase. -->
                    <xs:element name="currency" type="xs:string" minOccurs="0" maxOccurs="1" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

</xs:schema>
